package com.hinner.common.exception;

import com.hinner.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    // 专门处理运行时异常，如果运行时异常被抛出，会被这个方法捕获，并直接返回给前端
    @ExceptionHandler(RuntimeException.class)
    public Result handleException(RuntimeException e) {
        log.error("Exception: ", e);
        return Result.error(e.getMessage());
    }
}
